package com.itheima.exerciseTest.method20_29.method21;

import java.io.*;
import java.util.ArrayList;

public class Test3 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        User u1 = new User("itheima001", "123456", 23);
        User u2 = new User("itheima002", "697453", 24);
        User u3 = new User("itheima003", "142345", 25);
        ArrayList<User> al = new ArrayList<>();
        al.add(u1);
        al.add(u2);
        al.add(u3);
        // 创建对象序列化流
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("backBurner\\j.txt"));
        oos.writeObject(al);
        oos.close();

        // 创建对象反序列化流
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("backBurner\\j.txt"));
        ArrayList<User> all = (ArrayList<User>) ois.readObject();
        for (User user : all) {
            System.out.println(user);
        }
        ois.close();
    }
}
